package test.aat.dxfy.demo01;

import com.aat.dxfy.utils.Atools;

public class StringUTF {
	
	

	public static void main(String[] args) {
		//String s =URLDecoder.decode("&#32418;&#23725;&#21019;&#25237;");
		//System.out.println(chinaToUnicode("红岭创投"));
		
		//int[] ascs = string2ASCII("红岭创投");
		//System.out.println(Arrays.toString(ascs));
		System.out.println(chars2str("&#32418;&#23725;&#21019;&#25237;"));
	}
	
	public static String chars2str(String cs){
		String res="";
		String []ss =cs.split(";");
		for (int i = 0; i < ss.length; i++) {
			if(Atools.isNotEmpty(ss[i])){
				String vs=ss[i].substring(2, ss[i].length());
				char c = (char) Integer.parseInt(vs);
				res+=c;
			}
		}
		return res;
	}

	public static  String chinaToUnicode(String str){  
        String result="";  
        for (int i = 0; i < str.length(); i++){  
            int chr1 = (char) str.charAt(i);  
            if(chr1>=19968&&chr1<=171941){//汉字范围 \u4e00-\u9fa5 (中文)  
                result+="\\u" + Integer.toHexString(chr1);  
            }else{  
                result+=str.charAt(i);  
            }  
        }  
        return result;  
    }  
	
	
	public static int char2ASCII(char c) {  
        return (int) c;  
    }  
	
	public static int[] string2ASCII(String s) {// 字符串转换为ASCII码  
        if (s == null || "".equals(s)) {  
            return null;  
        }  
  
        char[] chars = s.toCharArray();  
        int[] asciiArray = new int[chars.length];  
  
        for (int i = 0; i < chars.length; i++) {  
            asciiArray[i] = char2ASCII(chars[i]);  
        }  
        return asciiArray;  
    }  
}
